package com.jcfk.system.service;

import com.jcfk.system.domain.po.OaRemindUser;
import com.jcfk.system.domain.query.OaRemindUserQuery;
import com.jcfk.system.domain.dto.OaRemindUserDTO;
import com.jcfk.system.dao.OaRemindUserDao;
import com.jcfk.common.business.service.BaseService;
import com.jcfk.common.web.domain.DataPage;
import com.jcfk.common.web.domain.RetResult;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.stereotype.Service;

import org.springframework.transaction.annotation.Transactional;
import com.jcfk.common.core.utils.BeanUtils;
import cn.hutool.core.util.StrUtil;
import com.jcfk.common.security.utils.SecurityUtils;
import com.alibaba.druid.util.StringUtils;

import java.util.List;
import java.util.ArrayList;
import java.util.stream.Collectors;
import com.jcfk.common.core.utils.IdUtils;
import static com.jcfk.common.core.utils.BeanUtils.convertList;

import java.util.Date;

/**
 * 提示范围
 *
 * @author awei
 * @email 522891237@gqq.com
 * @date 2024-04-15
 */
@Service
public class OaRemindUserService extends BaseService<OaRemindUserDao,OaRemindUser> {

    /**
     * OaRemindUser分页查询
     *
     * @param page  分页设置
     * @param query 查询条件
     * @return 分页查询结果
     */
    public DataPage<OaRemindUserDTO> queryByPage(DataPage<OaRemindUserDTO> page, OaRemindUserQuery query) {
        // 分页查询
        page = this.baseMapper.queryByPage(page, query);
        return page;
    }


        /**
     * 判断OaRemindUser是已经存在
     *
     * @param dto
     * @return
     */
    public RetResult<String> isValid(OaRemindUserDTO dto) {
        QueryWrapper<OaRemindUser> queryWrapper = new QueryWrapper<>();
                                                        
        return RetResult.ok();
    }

    /**
     * 插入提示范围
     *
     * @param dto 插入对象
     * @return
     */
    @Transactional(rollbackFor = Exception.class)
    public void insert(OaRemindUserDTO dto) {

        // 保存
        OaRemindUser item = new OaRemindUser();
        BeanUtils.copyProperties(dto, item);
        this.setDefaultValue(item);

        super.save(item);
    }

    /**
     * 更新提示范围
     *
     * @param dto 更新对象
     * @return
     */
    @Transactional(rollbackFor = Exception.class)
    public void update(OaRemindUserDTO dto) {

        // 保存
        OaRemindUser item = new OaRemindUser();
        BeanUtils.copyProperties(dto, item);

        // 默认数据
        this.setDefaultValue(item);

        super.updateById(item);
    }


    /**
     * 设置添加默认值
     *
     * @param item 添加对象
     */
    public void setDefaultValue(OaRemindUser item) {
        if (StrUtil.isEmpty(item.getCreatedUserId())) {
            item.setCreatedUserId(SecurityUtils.getUserId());
            item.setCreateTime(new Date());
        }
        item.setLastUpdatedUserId(SecurityUtils.getUserId());
        item.setLastUpdateTime(new Date());

    }

    /**
     * 根据主键获取提示范围信息
     *
     * @param id 主键
     * @return StandardCodeDTO
     */
    public OaRemindUserDTO get(String id) {
        // 查询数据
        OaRemindUser item = this.baseMapper.selectById(id);
            OaRemindUserDTO dto = new OaRemindUserDTO();
        try {
            BeanUtils.copyProperties(item, dto);
        } catch (RuntimeException e) {
            throw e;
        }

        return dto;
    }

    

    /**
     * 根据条件获取单表信息列表
     *
     * @param query 查询条件
     * @return List<OaRemindUserDTO>
     */
    public List<OaRemindUserDTO> getList(OaRemindUserQuery query) {
        // 查询条件
        QueryWrapper<OaRemindUser> qw = new QueryWrapper<>();
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                // 查询数据
        List<OaRemindUser> list = super.list(qw);

        return convertList(list, OaRemindUserDTO.class);
    }
}

